package com.fernfx.xingtan.my.ui;

import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.fernfx.xingtan.R;
import com.fernfx.xingtan.common.base.BaseActivity;
import com.fernfx.xingtan.common.webview.WebViewActivity;
import com.fernfx.xingtan.my.contract.SettingApplicationContract;
import com.fernfx.xingtan.my.presenter.SettingApplicationPresenter;
import com.fernfx.xingtan.utils.GlideUtil;
import com.fernfx.xingtan.utils.ToastUtil;
import com.fernfx.xingtan.view.dialog.ActionSheetDialog;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by admin on 2018/8/15.
 * 设置页面
 */

public class SettingApplicationActivity extends BaseActivity implements View.OnClickListener, SettingApplicationContract.View{
    @BindView(R.id.cache_size_tv)
    TextView cacheSizeTv;
    //presenter
    private SettingApplicationContract.Presenter presenter;
    //url
    private String helpUrl,aboutUsUrl;

    public static void start(Context context) {
        Intent intent = new Intent(context, SettingApplicationActivity.class);
        context.startActivity(intent);
    }

    @Override
    protected int getLayoutResId() {
        return R.layout.activity_my_setting_application;
    }

    @Override
    protected void initView() {
        presenter = new SettingApplicationPresenter<>();
        presenter.init(this);
    }

    @Override
    protected void initData() {
        freshenCacheImg();
        //加载webview的url
        loadWebViewUrl();
    }

    @OnClick({R.id.account_safe_rlt, R.id.message_setting_rlt, R.id.private_setting_rlt, R.id.clear_cache_rlt,R.id.quit_rlt,R.id.introduce_setting_rlt,R.id.help_setting_rlt})
    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.account_safe_rlt:
                AccountSafeActivity.start(mContext);
                break;
            case R.id.message_setting_rlt:
                //消息设置
                InformationSettingActivity.start(mContext);
                break;
            case R.id.private_setting_rlt:
                //隐私
                PrivateSettingActivity.start(mContext);
                break;
            case R.id.clear_cache_rlt:
                //清理缓存
                presenter.showClearCacheDialog(mContext);
                break;
            case R.id.quit_rlt:
                presenter.quitLogin(mContext);
                break;
            case R.id.introduce_setting_rlt:
                if (TextUtils.isEmpty(aboutUsUrl)) {
                    ToastUtil.showCentertoast("请稍候重试");
                    return;
                }
                WebViewActivity.start(mContext,aboutUsUrl,"关于我们");
                break;
            case R.id.help_setting_rlt:
                if (TextUtils.isEmpty(helpUrl)) {
                    ToastUtil.showCentertoast("请稍候重试");
                    return;
                }
                WebViewActivity.start(mContext,helpUrl,"帮助");
                break;
        }
    }

    public void loadWebViewUrl(){
        requestArgsMap.clear();
        presenter.getAboutUsUrl(requestArgsMap);
        presenter.getHelpUrl(requestArgsMap);
    }

    @Override
    public BaseActivity getActivity() {
        return this;
    }

    @Override
    public void freshenCacheImg(){
        cacheSizeTv.setText(GlideUtil.getCacheSize());
    }

    @Override
    public void setHelpUrl(String helpUrl) {
        this.helpUrl = helpUrl;
    }

    @Override
    public void setAboutUsUrl(String aboutUsUrl) {
        this.aboutUsUrl = aboutUsUrl;
    }
}
